﻿using EasyDentalMail.BO;
using EasyDentalMail.DAO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyDentalMail.View;

namespace EasyDentalMail
{
    public partial class Principal : Form
    {
        public Principal()
        {
            InitializeComponent();
            try
            {
                SqlConnect.AddCalendarID();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro com o banco " + ex.Message + " " +ex.InnerException +" " +ex.StackTrace);
            }
        }

        private void tmr1_Tick(object sender, EventArgs e)
        {
            atualizarAgenda();
        }

        private void atualizarAgenda()
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                
                GoogleBO bo = new GoogleBO();
                progressBar1.Minimum = 0;
                progressBar1.Value = 0;
                bo.cadastrarAgenda(progressBar1, label2);
                progressBar1.Value = 0;
                bo.removerEventoGoogleCalendar(progressBar1, label2);
                progressBar1.Value = 0;
                bo.pegarAgendamentosGoogle(progressBar1, label2);
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message + ex.InnerException + ex.StackTrace);
            }
            Cursor.Current = Cursors.Default;
        }


        private void Principal_Resize(object sender, EventArgs e)
        {
            if (FormWindowState.Minimized == this.WindowState)
            {
                ntfIcon.Visible = true;
                ntfIcon.ShowBalloonTip(500);
                this.Hide();
            }
        }

        private void ntfIcon_Click(object sender, EventArgs e)
        {
            ntfIcon.Visible = false;
            
            this.Show();
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            atualizarAgenda();
        }

    }
}
